<template>
  <a-card :bordered="false">
    <div class="table-page-search-wrapper">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="8" :sm="24">
            <a-form-item label="表名">
              <a-input placeholder="输入表名" v-model="queryParam.tableName"/>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-form-item label="表类型">
              <a-select
                placeholder="请选择表类型"
                v-model="queryParam.tableType"
                :options="tableTypeList"
              ></a-select>
            </a-form-item>
          </a-col>
          <a-col :md="8" :sm="24">
            <a-button @click="() => {this.queryPage()}" type="primary">查询</a-button>
            <a-button @click="() => queryParam = {}" style="margin-left: 8px">重置</a-button>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <div class="table-operator">
      <a-button @click="$refs.formModal.init('','add')" icon="plus" type="primary">新建</a-button>
    </div>
    <s-table
      bordered
      ref="table"
      :alert="alert"
      :data="loadData"
      :columns="columns"
      :rowKey="record => record.id"
      :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
    >
      <template slot="dbsync" slot-scope="text">
        <span v-if="text==='Y'" style="color:limegreen">已同步</span>
        <span v-if="text==='N'" style="color:red">未同步</span>
      </template>
      <span slot="action" slot-scope="text,record">
        <span v-action="'sys:user:update'">
          <a href="javascript:;" @click="edit(record)">编辑</a>
          <a-divider type="vertical" />
        </span>
        <a-dropdown>
          <a className="ant-dropdown-link">更多
            <a-icon type="down"/>
          </a>
          <a-menu slot="overlay">
            <a-menu-item>
              <a href="#" @click="sync">同步</a>
            </a-menu-item>
            <a-menu-item>
              <a href="#" @click="funTesting">功能测试</a>
            </a-menu-item>
            <a-menu-item>
              <a-popconfirm title="确定删除吗" @confirm="del(record)" okText="是" cancelText="否">
                <a-icon slot="icon" type="question-circle-o" style="color: red"/>
                <a href="javascript:" style="color: red">删除</a>
              </a-popconfirm>
            </a-menu-item>
            <a-menu-item>
              <a href="#" @click="removeVal">移除</a>
            </a-menu-item>
          </a-menu>
        </a-dropdown>
      </span>
    </s-table>
    <form-modal
      ref="formModal"

    />
  </a-card>
</template>

<script>
import { TableMixin } from '@/mixins/TableMixin'
import { fetchList } from '@/api/form/head'
import formModal from './form-modal'
const tableTypeList = [
  {
    label: '单表',
    value: '0'
  },
  {
    label: '主表',
    value: '1'
  },
  {
    label: '附表',
    value: '2'
  }
]
export default {
  name: 'FormHead',
  mixins: [TableMixin],
  components: {
    formModal
  },
  data () {
    return {
      tableTypeList,
      columns: [
        {
          title: '序号',
          width: '10%',
          customRender: (text, record, index) => {
            return (
              <div>
                {index + 1}
              </div>
            )
          }
        },
        { title: '表名', dataIndex: 'tableName', sorter: true },
        { title: '表类型', dataIndex: 'tableType', sorter: true },
        { title: '表描述', dataIndex: 'tableTxt' },
        { title: '表版本', dataIndex: 'tableVersion' },
        { title: '是否同步', dataIndex: 'isDbSynch', sorter: true, scopedSlots: { customRender: 'dbsync' } },
        { title: '创建时间', dataIndex: 'createTime', sorter: true },
        { title: '操作', scopedSlots: { customRender: 'action' } }
      ],
      queryParam: {
        tableName: '',
        tableType: undefined
      },
      loadData: parameter => {
        return fetchList(
          Object.assign(parameter, this.queryParam)
        ).then(res => {
          return res.data
        })
      }
    }
  },
  methods: {
    // 编辑
    edit (record) {

    },
    // 删除  顺表删除表
    del (record) {

    },
    // 移除 不删除表 只删除字典
    removeVal (record) {

    },
    // 功能测试
    funTesting (record) {

    },
    // 同步数据库
    sync (record) {

    }
  }
}
</script>

<style scoped>

</style>
